package com.zhu.dao;

import com.zhu.pojo.Hobby;
import com.zhu.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class HobbyDao {
    private Connection connection;
    private PreparedStatement preparedStatement;
    private ResultSet resultSet;

    public List<Hobby> getHobby() throws SQLException {
        List<Hobby> hobbyList = new ArrayList<>();

        connection = JDBCUtil.getInstance().getConnection();
        preparedStatement = connection.prepareStatement("select * from hobby");
        resultSet = preparedStatement.executeQuery();
        Hobby hobby ;
        while (resultSet.next()) {
            hobby = new Hobby();
            hobby.setHid(resultSet.getInt("hid"));
            hobby.setHname(resultSet.getString("hname"));
            hobbyList.add(hobby);
        }
        return hobbyList;
    }
}
